﻿Imports System.Data
Imports VSModel
Imports Cls_Common
Partial Class Control_Customer_PrintPreview
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            'If Request("PrintedDate") Is Nothing Then
            BindToHotel()

            'End If


        End If

    End Sub
    Protected Sub BindToHotel()
        Using _data As New VSEntities
            Dim _HotelId As Integer = Session("HotelId")
            Dim p = (From q In _data.Hotels Where q.Id = _HotelId Select q).FirstOrDefault
            If Not p Is Nothing Then
                lblHotelName.Text = p.HotelName
                lblAddress.Text = p.Address & ", " & p.Ward & ", " & p.District
                lblFax.Text = p.Fax
                lblPhone.Text = p.Phone
                ltrNgayThangNam.Text = "ngày " & Now.Day.ToString & " tháng " & Now.Month.ToString & " năm " & Now.Year.ToString
                ltrQuanHuyen.Text = p.Ward & ", " & p.District
                ' show thong tin khach san neu co chon ngay
                'If Not Request("date") Is Nothing AndAlso Request("date") <> "" Then
                '    Dim _PrintedDate As Date = StringToDate(Request("date"))
                '    Dim k = (From q In _data.Customers Where q.HotelId = _HotelId And q.FromDate = _PrintedDate Order By q.FullName Descending Select q).ToList

                '    With rptPrintedList
                '        .DataSource = k
                '        .DataBind()
                '    End With
                'Else
                '    'show customer curdate
                '    Dim curDate As Date = Now.Date
                '    Dim k = (From q In _data.Customers Where q.HotelId = _HotelId And q.FromDate = curDate Order By q.FullName Descending Select q).ToList

                '    With rptPrintedList
                '        .DataSource = k
                '        .DataBind()
                '    End With

                '    'update printed date
                '    ' _data.uspUpdatePrintedDate(_HotelId, Now.Date)


                'End If
                'sua ngay 31/01/2015

                Dim _fDate As Date = StringToDate(Request("fDate"))
                Dim _tDate As Date = StringToDate(Request("tDate"))
                Dim _strCus As String = Request("cus")
                Dim _country As String = Request("country")
                Dim _hochieu As String = Request("hc")


                'So ban ghi muon the hien tren trang

                Dim intPag_Size As Int32 = 1000000
                Dim cus As List(Of uspCustomerSelectAll_Result) = _data.uspCustomerSelectAll(_strCus, _HotelId, _fDate, _tDate, _country, _hochieu, 1, intPag_Size).ToList
                If cus.Count > 0 Then
                    With rptPrintedList
                        .DataSource = cus
                        .DataBind()
                    End With
                End If

            End If

        End Using

    End Sub

    Protected Sub rptPrintedList_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptPrintedList.ItemDataBound
        Using _data As New VSEntities
            Dim obj As Object = e.Item.DataItem
            Dim cusId As Integer = obj.CustomerId
            Dim row As Customer = (From q In _data.Customers Where q.CustomerId = cusId Select q).FirstOrDefault
            Dim lblStt As Label = CType(e.Item.FindControl("lblStt"), Label)
            lblStt.Text = e.Item.ItemIndex + 1
            Dim lblFullName As Label = CType(e.Item.FindControl("lblFullName"), Label)
            lblFullName.Text = row.FullName
            Dim lblSex As Label = CType(e.Item.FindControl("lblSex"), Label)
            If Not row.Sex Is Nothing AndAlso row.Sex = 1 Then
                lblSex.Text = "Nam"
            Else
                lblSex.Text = "Nữ"
            End If
            Dim lblDateOfBirth As Label = CType(e.Item.FindControl("lblDateOfBirth"), Label)

            lblDateOfBirth.Text = CType(row.DateOfBirth, Date).ToString("dd/MM/yyyy")
            Dim lblCountryName As Label = CType(e.Item.FindControl("lblCountryName"), Label)
            lblCountryName.Text = row.CountryName

            Dim lblSoLoaiHoChieu As Label = CType(e.Item.FindControl("lblSoLoaiHoChieu"), Label)

            lblSoLoaiHoChieu.Text = row.PasspostNumber & ", " & row.PasspostType

            'Dim lblPassportNumber As Label = CType(e.Item.FindControl("lblPassportNumber"), Label)
            'lblPassportNumber.Text = row.PasspostNumber

            'Dim lblExpireDate As Label = CType(e.Item.FindControl("lblExpireDate"), Label)
            'If Not row.ExpiredDate Is Nothing Then
            '    lblExpireDate.Text = CType(row.ExpiredDate, Date).ToString("dd/MM/yyyy")
            'End If
            'Loại, thời hạn, số, ngày cấp, cơ quan cấp thị thực
            Dim lblThiThuc As Label = CType(e.Item.FindControl("lblThiThuc"), Label)

            lblThiThuc.Text = row.LoaiThiThuc
            If Not row.ThoiHanThiThuc Is Nothing AndAlso row.ThoiHanThiThuc <> #1/1/1900# Then
                lblThiThuc.Text = lblThiThuc.Text & ", " & CType(row.ThoiHanThiThuc, Date).ToString("dd/MM/yyyy")
            End If
            'so thi thuc
            If Not row.SoThiThuc Is Nothing Then
                lblThiThuc.Text = lblThiThuc.Text & ", " & row.SoThiThuc
            End If
            'ngay cap
            If Not row.NgayCapThiThuc Is Nothing AndAlso row.NgayCapThiThuc <> #1/1/1900# Then
                lblThiThuc.Text = lblThiThuc.Text & ", " & CType(row.NgayCapThiThuc, Date).ToString("dd/MM/yyyy")
            End If
            ' co quan cap
            If Not row.CoQuanCapThiThuc Is Nothing Then
                lblThiThuc.Text = lblThiThuc.Text & ", " & row.CoQuanCapThiThuc
            End If


            'ngay nhap canh
            Dim lblNgayNhapCanh As Label = CType(e.Item.FindControl("lblNgayNhapCanh"), Label)
            If Not row.EntryDate Is Nothing AndAlso row.EntryDate <> #1/1/1900# Then
                lblNgayNhapCanh.Text = CType(row.EntryDate, Date).ToString("dd/MM/yyyy")
            End If
            'cua khau nhap canh
            Dim lblCuaKhauNhapCanh As Label = CType(e.Item.FindControl("lblCuaKhauNhapCanh"), Label)
            lblCuaKhauNhapCanh.Text = row.GateName


            Dim lblMucDichNhapCanh As Label = CType(e.Item.FindControl("lblMucDichNhapCanh"), Label)
            lblMucDichNhapCanh.Text = row.EntryPurposeName


            Dim lblFromDate As Label = CType(e.Item.FindControl("lblFromDate"), Label)
            If Not row.FromDate Is Nothing AndAlso row.FromDate <> #1/1/1900# Then
                lblFromDate.Text = CType(row.FromDate, Date).ToString("dd/MM/yyyy")
            End If

            Dim lblToDate As Label = CType(e.Item.FindControl("lblToDate"), Label)
            If Not row.ToDate Is Nothing AndAlso row.ToDate <> #1/1/1900# Then
                lblToDate.Text = CType(row.ToDate, Date).ToString("dd/MM/yyyy")

            End If
        End Using

     

        'Dim lblGreetingOrganization As Label = CType(e.Item.FindControl("lblGreetingOrganization"), Label)
        'lblGreetingOrganization.Text = row.AgencyWelcome


    End Sub
End Class
